package pack0819;

import java.util.Arrays;
import java.util.Scanner;

public class DemoA {
    Scanner in = new Scanner(System.in);
    public void zhangHao(){
        System.out.println("请输入邮箱：");
        String email = in.next();
        int i1 = email.indexOf("@");
        int i2 = email.indexOf(".");
        if(i1!=-1&&i2!=-1&&i1<i2){
            System.out.println("请输入作业：");
            String name = in.next();
            String name1 = name.toLowerCase();
            boolean b = name1.endsWith(".java");
            if(b){
                System.out.println("作业提交成功！");
            }else{
                System.out.println("作业提交失败！");
            }
        }else{
            System.out.println("邮箱输入错误！");
        }
    }
    //如何产生String类型对象
    public void a() {
        //产生了一个空字符串
        String str1 = new String();
        //以字符串（abc）为蓝本复制产生了一个新的字符串str2，abc
        String str2 = new String("abc");
        //以字符数组为蓝本复制产生了一个新的字符串str3，abcde
        char[] c1 = {'a','b','c','d','e'};
        String str3 = new String(c1);
        //以字符数组为蓝本，从第三个开始截取，一共截取两个复制产生了一个新的字符串str4,cd
        String str4 = new String(c1,2,2);
        // 以字节数组为蓝本，复制产生了一个新的字符串str5,abcde
        byte[] c2 = {97,98,99,100,101};
        String str5 = new String(c2);
        //以字节数组为蓝本，从第2个开始截取，一共截取3个复制产生了一个新的字符串str6,bcd
        String str6 = new String(c2,1,3);
        //产生了一个字符串str7,值：abc
        String str7 = "abc";
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str3);
        System.out.println(str4);
        System.out.println(str5);
        System.out.println(str6);
        System.out.println(str7);

    }
    //判断产生的值和位置
    public void b(){
        String s1 = "abc";
        String s2 = "abc";
        System.out.println(s1==s2);
        String s3 = new String("abc");
        String s4 = new String("abc");
        System.out.println(s3==s4);
    }
    //1.返回指定索引处的char值,charAt 2.在字符串末尾链接其他字符串,concat
    public void c1(){
        String str = "sauhflauhf";
        char c1 = str.charAt(6);//返回指定索引处的char值
        System.out.println(c1);
        String str1 = str.concat("aaaa");//在字符串末尾链接其他字符串
        String str2 = str+"bbbb";
        System.out.println(str1);
        System.out.println(str2);
    }
    //equals(s2)将字符串与指定字符串比较
    public void c2(){
        String s1 = new String("aaa");
        String s2 = new String("aaa");
        System.out.println(s1==s2);
        boolean b1 = s1.equals(s2);//将字符串与指定字符串比较，注：比较的是值，区分大小写
        boolean b2 = s1.equalsIgnoreCase(s2);//不区分大小写
        System.out.println(b1);
        System.out.println(b2);
    }
    //判断开始startsWith("aaa")和结束endsWith("aaa")的字符串是否有指定的字符串
    public void c3(){
        String a = "skhfisjfoiaaa";
        boolean b1 = a.endsWith("aaa");
        boolean b2 = a.startsWith("aaa");
        System.out.println(b1);
        System.out.println(b2);
    }
    //trim()去掉字符串开始和结束的空格
    public void c4(){
        String a = "       dfsf       sdsfsf     ";
        String b = a.trim();
        System.out.println(b);
    }
    //length()返回字符串的长度
    public void c5(){
        String a = "adfagad";
        int len = a.length();
        System.out.println(len);
    }
    //判断指定字符串在字符串中开始第一个indexOf("f")和末尾第一个lastIndexOf("f")的位置
    public void c6(){
        String s = "afhakflakjfls";
        int index1 = s.indexOf("f");
        int index2 = s.lastIndexOf("f");
        int index3 = s.indexOf("6");
        System.out.println(index1);
        System.out.println(index2);
        System.out.println(index3);
    }
    //s.substring截取
    public void c7(){
        String s = "akjfkah";
        //截取第三个以后的，从零数
        String s1 = s.substring(3);
        //从第三个开始（从零数）到第五个结束（从一数）
        String s2 = s.substring(3,5);
        System.out.println(s1);
        System.out.println(s2);
    }
    //将字符串变成全大写toUpperCase()和全小写toLowerCase()，数字除外
    public void c8(){
        String s = "sfhsk3jij";
        String s1 = s.toUpperCase();
        String s2 = s.toLowerCase();
        System.out.println(s1);
        System.out.println(s2);
    }
    //把字符串转变成数组形式
    public void c9(){
        String s = "sd,fds,fsdf,ef,fsv";
        char[] chars = s.toCharArray();
        byte[] bytes = s.getBytes();
        String[] strings = s.split(",f");
        System.out.println(Arrays.toString(chars));
        System.out.println(Arrays.toString(bytes));
        System.out.println(Arrays.toString(strings));
    }
    //replace("f","66")用新的字符串替换老字符串
    public void c10(){
        String s = "sfsllfaks";
        String s1 = s.replace("f","66");
        System.out.println(s1);
    }
    //intern()返回字符串对象的规范化表示形式
    public void c11(){
        String s1 = "aa";
        String s2 = "aa";
        String s3 = new String("aa");
        String s4 = new String("aa");
        String s5 = s4;
        System.out.println(s1==s2);
        System.out.println(s3==s4);
        System.out.println(s1==s3);
        System.out.println(s1=="aa");
        System.out.println(s4==s5);
        System.out.println("------------------");
        String s6 = s3.intern();
        String s7 = s4.intern();
        System.out.println(s6==s7);
    }
    //字符串的赋值和长度
    public void c12(){
        String s1 = null;
        String s2 = "";
        String s3 ;
        String s4 = new String();
        //System.out.println(s1.length());//null值没有长度
        System.out.println(s2.length());
        //System.out.println(s3);没有处值不能输出
        System.out.println(s4.length());
    }
    public static void main(String[] args) {
        new DemoA().c9();
    }
}
